package com.fenghongzhang.day008;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    private ScrollView sv;

    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView(); //1



        //动态添加一个图片和一个文字
        LinearLayout linearLayout = new LinearLayout(this);
        TextView textView = new TextView(this);
        textView.setText("哈哈");

        ImageView imageView = new ImageView(this);
        imageView.setImageResource(R.mipmap.ic_launcher);

        linearLayout.addView(textView);
        linearLayout.addView(imageView);

        sv.addView(linearLayout);




        sv.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                Log.i(TAG, "onScrollChange: "+scrollX);
                Log.i(TAG, "onScrollChange: "+oldScrollX);

                Log.i(TAG, "onScrollChange: "+scrollY);
                Log.i(TAG, "onScrollChange: "+oldScrollY);


                if(scrollY >= 200){
                    Toast.makeText(MainActivity.this, "呵呵", Toast.LENGTH_SHORT).show();
                }

            }
        });

    }


    private void initView() {
        sv = (ScrollView) findViewById(R.id.sv);
    }
}
